@include('admin::layouts.header')
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>文章管理</legend>
    </fieldset>
	<div class="demoTable layui-row">
		<div class="layui-form layui-form-pane" style="float:left;">
			<div class="layui-form-item">
				<label class="layui-form-label">快捷查询</label>
				<div class="layui-input-inline layui-form">
					<input class="layui-input" name="key" id="key" placeholder="请输入标题">
				</div>
			</div>
        </div>
		<div class="layui-form layui-form-pane" style="float:left;width:460px">
			<div class="layui-form-item">
				<label class="layui-form-label">添加时间</label>
				<div style="width:72%" class="layui-input-inline layui-form">
					<input style="width:100%" type="text" class="layui-input" id="created_at" placeholder="请选择时间">
				</div>
			</div>	
		</div>
		<div class="layui-form layui-form-pane" style="float:left">
			<div class="layui-form-item">
				<label class="layui-form-label">状态</label>
				<div class="layui-input-inline layui-form">
					<select id="status_d">
						<option value="">请选择</option>
						@foreach($status as $key=>$value)
							<option value="{{$key}}">{{$value}}</option>
						@endforeach
					</select>
				</div>
			</div>		
		</div>
		<div class="layui-form layui-form-pane" style="float:left">
			<div class="layui-form-item">
				<label class="layui-form-label">是否推荐</label>
				<div class="layui-input-inline layui-form">
					<select id="open_d">
						<option value="">请选择</option>
						@foreach($open_list as $key=>$value)
							<option value="{{$key}}">{{$value}}</option>
						@endforeach
					</select>
				</div>
			</div>		
		</div>
		<div class="layui-form layui-form-pane" style="float:left">
			<div class="layui-form-item">
				<label class="layui-form-label">所属栏目</label>
				<div class="layui-input-inline layui-form">
					<select id="blog_column_id">
					<option value="">请选择</option>
					@foreach($column_list as $k=>$v)
					<option value="{{$v->id}}">{{$v->lefthtml}}{{$v->title}}</option> 
					@endforeach
				</select>
				</div>
			</div>		
		</div>
    </div>
	<div class="demoTable layui-row">
		<button class="layui-btn" style="margin-left:30px;margin-top:15px;" id="search" data-type="reload">查询</button>
		<a href="{{route('blog_admin.article.index')}}" style="margin-top:15px;" class="layui-btn">重置</a>
	</div>
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>
@include('admin::layouts.footer')
<script type="text/html" id="barDemo">
	<a class="layui-btn layui-btn-warm layui-btn-xs" onclick="push_url(@{{d.id}})">文章推送</a>
    <a href="/blog_admin/article/@{{d.id}}/edit" class="layui-btn layui-btn-xs">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/html" id="status">
	<input type="checkbox" name="status" value="@{{d.id}}" lay-skin="switch" lay-text="{!! config('admin.enabled') !!}|{!! config('admin.forbidden') !!}" lay-filter="status" @{{ d.status == 1 ? 'checked' : '' }}> 
</script>
<script type="text/html" id="open">
	<input type="checkbox" name="open" value="@{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="open" @{{ d.open == 1 ? 'checked' : '' }}> 
</script>
<script type="text/html" id="sort">
    <input name="@{{d.id}}" data-id="@{{d.id}}" class="list_order layui-input" value=" @{{d.sort}}" size="10"/>
</script>
<script type="text/html" id="image">
    <img src="@{{d.image}}" style="width:50px;height:100%;"/>
</script>
<script type="text/html" id="topBtn">
   <a href="{{route('blog_admin.article.create')}}" class="layui-btn layui-btn-sm">添加</a>
   <button type="button" class="layui-btn layui-btn-sm layui-btn-danger" onclick="delAll()">批量删除</button>
</script>
<script>
    layui.use(['table','form'], function() {
        var table = layui.table,form = layui.form,$ = layui.jquery;
        var tableIn = table.render({
			id: 'ad',
            elem: '#list',
            url: "{{route('blog_admin.article.data')}}",
            method:'get',
			toolbar: '#topBtn',
			title:'图片管理',
			page: true,
            cols: [[
				{checkbox: true, fixed: true}
                ,{field:'id', title: '编号', width:100,align: 'center',fixed: true,sort: true}
                ,{field:'title', title: '标题',align: 'center', width:200}
                ,{field:'image', title: '图片',align: 'center', width:200, toolbar: '#image'}
                ,{field:'column', title: '所属栏目',align: 'center', width:200}
                ,{field:'created_at', title: '添加时间',align: 'center', width:200,sort: true}
                ,{field:'status', title: '状态',width:150,align: 'center',toolbar: '#status'}
                ,{field:'open', title: '是否推荐',width:150,align: 'center',toolbar: '#open'}
				,{field: 'sort',align: 'center', title: '排序', width: 80, templet: '#sort'}
                ,{width:300, title: '操作',align:'center',align: 'center', toolbar: '#barDemo'} 
            ]],
			limit: "{!! config('admin.common_limit') !!}"
        });
		//搜索
        $('#search').on('click', function () {
			var created_at 		= $('#created_at').val();
			var status  		= $('#status_d').val();
			var key  			= $('#key').val();
			var blog_column_id  = $('#blog_column_id').val();
			var open = $('#open_d').val();
            if ($.trim(created_at) === '' && $.trim(status) === '' && $.trim(key) === '' && $.trim(blog_column_id) === '' && $.trim(open) === ''){
                layer.msg("{!! config('admin.query_condition') !!}", {icon: 0});
                return;
            }
			tableIn.reload({
				where: {created_at:created_at,status:status,key:key,blog_column_id:blog_column_id,open:open}
			});
        });
        form.on('switch(status)', function(obj){
            loading =layer.load(1, {shade: [0.1,'#fff']});
            var id = this.value;
            var status = obj.elem.checked===true?1:0;
            $.post('/blog_admin/article/'+id+'/status',{_method:'PUT',status:status},function (res) {
				layer.close(loading);
				if (res.status == 1) {  
						layer.msg(res.msg,{time:1000,icon:1});
				}else{
				   layer.msg(res.error,{time:1000,icon:2},function(){
						location.href = res.url;
						});
					return false;
				}
            })
        });
		push_url = function(id){
			loading =layer.load(1, {shade: [0.1,'#fff']});
			$.get("{{route('blog_admin.article.push_url')}}",{id:id},function (res) {
				layer.close(loading);
				if (res.status == 1) {  
						layer.msg(res.msg,{time:1000,icon:1});
				}else{
				   layer.msg(res.error,{time:1000,icon:2},function(){
						location.href = res.url;
					});
					return false;
				}
            })
		};
		form.on('switch(open)', function(obj){
            loading =layer.load(1, {shade: [0.1,'#fff']});
            var id = this.value;
            var open = obj.elem.checked===true?1:0;
            $.post('/blog_admin/article/'+id+'/open',{_method:'PUT',open:open},function (res) {
				layer.close(loading);
				if (res.status == 1) {  
						layer.msg(res.msg,{time:1000,icon:1});
				}else{
				   layer.msg(res.error,{time:1000,icon:2},function(){
						location.href = res.url;
						});
					return false;
				}
            })
        });
		$('body').on('blur','.list_order',function() {
		   loading =layer.load(1, {shade: [0.1,'#fff']}); 
           var id = $(this).attr('data-id');
           var sort = $(this).val();
           $.post('/blog_admin/article/'+id+'/sorts',{_method:'PUT',sort:sort},function(res){
                layer.close(loading);
				if (res.status == 1) {  
						layer.msg(res.msg,{time:1000,icon:1});
				}else{
				   layer.msg(res.error,{time:1000,icon:2},function(){
						location.href = res.url;
						});
					return false;
				}
           })
        });
    });
</script>
@include('admin::layouts.delete_ajax',['url'=>route('blog_admin.article.destroy')])
@include('admin::layouts.delete_all_ajax',['url'=>route('blog_admin.article.destroy_all')])
</body>
</html>